package org.tloss.web.editor.form.editors.command;

import java.util.Collections;

import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import org.tloss.web.editor.model.command.Replace;
import org.tloss.web.editor.utils.VariableBrowser;

public class ReplaceProperty implements IPropertySource {
	private IPropertyDescriptor[] descriptors;
	public static final String NAME_PRO = "NAME_PRO";
	public static final String VARIABLE_PRO = "VARIABLE_PRO";
	private Replace command;
	private IResourceChangeListener listener;

	public ReplaceProperty() {
		descriptors = new IPropertyDescriptor[2];
		descriptors[0] = new PropertyDescriptor(VARIABLE_PRO, "Value") {
			public CellEditor createPropertyEditor(Composite parent) {
				DialogCellEditor cellEditor = new DialogCellEditor(parent) {
					@SuppressWarnings("unchecked")
					@Override
					protected Object openDialogBox(Control arg0) {
						VariableBrowser dialog = new VariableBrowser(
								arg0.getShell());
						dialog.setSupportedVariable(Collections.EMPTY_LIST);
						dialog.open();
						return command;
					}
				};
				return cellEditor;
			};
		};
		descriptors[1] = new TextPropertyDescriptor(NAME_PRO, "Name");
	}

	public Replace getCommand() {
		return command;
	}

	public void setCommand(Replace command) {
		this.command = command;
	}

	public IResourceChangeListener getListener() {
		return listener;
	}

	public void setListener(IResourceChangeListener listener) {
		this.listener = listener;
	}

	@Override
	public Object getEditableValue() {
		return this;
	}

	@Override
	public IPropertyDescriptor[] getPropertyDescriptors() {
		return descriptors;
	}

	@Override
	public Object getPropertyValue(Object arg0) {
		return "";
	}

	@Override
	public boolean isPropertySet(Object arg0) {
		return false;
	}

	@Override
	public void resetPropertyValue(Object arg0) {

	}

	@Override
	public void setPropertyValue(Object arg0, Object arg1) {

	}

}
